<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core"  prefix="c"%>
<%@ taglib prefix="f" uri="http://www.springframework.org/tags/form"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/fmt" prefix="fmt"%>
<%
	String path=request.getContextPath();
%>    

<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>
	<link href="/resources/css/bootstrap-4.3.1/css/bootstrap.css" rel="stylesheet">
	<script type="text/javascript" src="/resources/js/jquery-3.2.1/jquery.js"></script>
	<script type="text/javascript" src="/resources/js/jqueryvalidate/jquery.validate.js"></script>
	<script type="text/javascript" src="/resources/js/jqueryvalidate/localization/messages_zh.js"></script>
	<script type="text/javascript" src="/resources/css/bootstrap-4.3.1/js/bootstrap.js"></script>
</head>
<body>
	<h3>更新投票 </h3>
	<form name = "updateVote">
	  <div class="form-group">
	    <label for="exampleInputEmail1">问题</label>
	    <p>${voteTopic.name }</p>
	    <input type = "hidden" value = "${voteTopic.id }" name = "topic_id">
	  </div>
	  <div class="form-group">
	    <label for="exampleInputPassword1">投票项</label>
	  	 <select class="form-control" id = "itemList"  name = "id" >
		 	<c:forEach items="${voteTopic.list }" var="item">
		 		<option value = "${item.id }" >${item.name }</option>
		 	</c:forEach>     
		 </select>
	  </div>
	  <div class="form-group">
	    <label for="exampleInputPassword1">投票数</label>
	    <input type="text" class="form-control" name = "votes" id = "countVotes" >
	  </div>
	  
	  <input type="button" class="btn btn-primary" onclick = "submitVote()" value = "修改"/>
	</form>
	
	<script type="text/javascript">
		
	var tid = 0;
	
		$("#itemList").change(function(){
			
			tid = $(this).val();
			
			$.post("showCount",{id:${voteTopic.id },tid:tid},function(msg){
				
				$("#countVotes").val(msg);
				
			})	
		})
	
		
		function submitVote(){
			
			alert("11");
			
			$.post("updateVote",$("form[name='updateVote']").serialize(),function(msg){
				
				if(msg>0){
					
					alert("修改成功！");
					location = "showAll";
				}else{
					alert("修改失败");
				}
				
				
			})
				
		}
	
	
	</script>


</body>
</html>